var url 			= "http://203.236.20.167:9000/service.pe?";
var xmlHandler 		= new SKTXmlHandler;
var database 		= new Database();
var selectTab   	= 1;		//현재탭
var modifying 		= 0;		//선택모드
var tabHidden		= 0;
var widgetBtn 		= 0;		//위젯활성화
var allChecked 		= 0;		//모두선택
var updateTime 		= "";		//최종업데이트
var key_theme 		= "theme";	
var selectTheme 	= "white";
var array_db 		= null;
var longClickTarget = null;
var authInfo		= null;
var currentPage		= null;		//리스트의 현재페이지
var isAddData		= false;	//리스트에 추가내용 여부
var addListDataSet 	= new Array();
var inputValue4 	= null;
var mailIdAr		= null;
var mailChangeKeyAr	= null;
var searchRangeAr	= {1:"G", 2:"G", 3:"G", 4:"G"}; 
//각 탭 키워드검색 범위 B:받은날짜이후, C:받은날짜이전, D:제목, E:받는이, F:보낸이, G:전체

function init() {

	if( authInfo==undefined || authInfo==null ){
		if(alopexController.parameters["authInfo"]!=null){
			authInfo=alopexController.parameters["authInfo"];
			currentPage = 1;
			receiveMailRequest();
		}else{
			gmpUtil.getAuthInfo(authCallback, authErrorCallback);
		}
	}else{
		currentPage = 1;
		receiveMailRequest();
	}
	
	selectTab   = 1;	// 선택된 탭
	modifying 	= 0;	// 수정중
	allChecked 	= 0;	// 모두 선택
	currentPage = 1;	// 현재페이지
	mailIdAr	= new Array();
	mailChangeKeyAr = new Array();
	
	initHandler();		// 이벤트 핸들러 등록
	checkFlatform();	// 디바이스 확인
	checkTheme();		// 배경테마 확인
	
	tabDisplay( "recieveMailBox_tab" );
	
    setLocalMenu();
    
    //최종업데이트날짜
    updateTime = new VTIDateManager().getDate( "mm.dd KAMPM APMhh:mi" );
    updatePanelTxtField.setText( updateTime );
    updateTime = new VTIDateManager().getDate( "yyyy-mm-dd" );
	
    NgmsDBinit()

    modifyListClose();
	list1.refresh(); 
	searchSelLabel1_1.setData("받은 편지함 - 전체");
	scrollView1.refresh();
	
	//signature
	if(preference.getString("signature", "") == "")
		preference.putString("signature", "서명입니다!");
	
}

//GMP AuthKey
function authCallback(successMessage){
	
	authInfo	 = successMessage;
	var loTmpArr = successMessage.split('&');
	var loKeyArr = new Array();
	
	for( var i = 0; i < loTmpArr.length; i++ ){
		
		var tmpArr = loTmpArr[ i ].split('=');
		loKeyArr[ i ] = tmpArr[1];
		
	}

	if( loKeyArr[5] == "null"){

		init();
	
	} else if ( loKeyArr[5] == null ){
		
		alert("authCallback 에러 확인요");
		gmpUtil.getAuthInfo(authCallback, authErrorCallback);
		
	}else {

		currentPage = 1;
		mailIdAr	= new Array();
		mailChangeKeyAr = new Array();
		receiveMailRequest();
	
	}
}

function authErrorCallback(errorMessage){

	if(errorMessage == "AuthError") {
		
		alert("로그인 정보가 없습니다. 로그인 하십시오.");
		gmpUtil.loginGmp(authCallback, authErrorCallback);
	
	} else {
	
		log.error("errorMessage :: " + errorMessage);
		alert("에러 : " + errorMessage );
		nativeUI.dismissProgressDialog();
		
	}
}

//받은편지함 List HTTP 통신 request
function receiveMailRequest(searchWord){
	
	nativeUI.showProgressDialog();	
	
	var mailBoxType = new Object();
	
	switch (selectTab){
	
		case 1:
			mailBoxType = "I"
			break;
			
		case 2:
			mailBoxType = "S"
			break;
			
		case 3:
			mailBoxType = "D"
			break;
			
		default:
			mailBoxType = "F"
			break;
	}
	
	var tmpParams = new Object();
	tmpParams["function"] 		= "COMMON_MAIL_LIST";
	tmpParams["mailBoxType"] 	= mailBoxType;

	//검색어가 있다면
	if( searchWord != undefined ){
		
		currentPage = 1;
		mailIdAr	= new Array();
		mailChangeKeyAr = new Array();
		
		alert("선택한탭 : " + selectTab + ", searchType : " + searchRangeAr[selectTab]);
		tmpParams["searchType"] = searchRangeAr[selectTab];
		tmpParams["searchWord"] = searchWord;
	}

	tmpParams["page"]		 	= currentPage;
	tmpParams["countPerPage"] 	= "20";

	// 사용자폴더일때 구현필요
	//tmpParams["ID"] 			= URLEncode("");	//사용자폴더일때
	//tmpParams["CHANGEKEY"] 	= URLEncode("");	//사용자폴더일때
	
	var requestXml = xmlHandler.make(tmpParams);
	log.log("request : " + url + authInfo + "\n params : \n" + requestXml);
	
	if(authInfo==undefined){
		
		gmpUtil.loginGmp(authCallback, authErrorCallback);
		
	} else {
		
		http.request( url + authInfo, "POST", tmpParams, getMailListCallback, failureCallback );
		
	}
}

//GMP 서버에 쿼리스트링으로 전달전 ID만 Encode하여 전달
function URLEncode (clearString) {
	  var output = '';
	  var x = 0;
	  clearString = clearString.toString();
	  var regex = /(^[a-zA-Z0-9_.]*)/;
	  while (x < clearString.length) {
	    var match = regex.exec(clearString.substr(x));
	    if (match != null && match.length > 1 && match[1] != '') {
	    output += match[1];
	      x += match[1].length;
	    } else {
	      if (clearString[x] == ' ')
	        output += '+';
	      else {
	        var charCode = clearString.charCodeAt(x);
	        var hexVal = charCode.toString(16);
	        output += '%' + hexVal.toUpperCase();
	      }
	      x++;
	    }
	  }
	  return output;
}

//받은편지함 리스트
function getMailListCallback() {

	var xmlStr = http.response;	
	var lotmpDataSet   	= xmlHandler.parse(xmlStr);

	//result 처리
	var tmpxml = (new DOMParser()).parseFromString(xmlStr, "text/xml");
	var result = tmpxml.getElementsByTagName("result")[0].firstChild.nodeValue;
	var resultMessage = tmpxml.getElementsByTagName("resultMessage")[0].firstChild.nodeValue;
	
	if(result == "1000") {
		var loList			= eval("("+"list"+ selectTab +")");
		var reDateDataSet 	= new Array();
	
		//메일받은날짜표기
		for(var i=0; i<lotmpDataSet.getList("mailInfoList").length; i++){
			
			var tmpDate 	= lotmpDataSet.getList("mailInfoList")[i].get("receivedDate");
			var tmpAr		= tmpDate.split('T');
			var tmpResult	= "";
			
			if(updateTime==tmpAr[0]){
				
				var ttmpAr  = tmpAr[1].split(':');
				var tmpX 	= "";

				if( ttmpAr[0] > 12 ){
					tmpX = "오후 ";
					tmpX += (parseInt(ttmpAr[0])-12 < 10) ? "0" + (parseInt(ttmpAr[0])-12) : (parseInt(ttmpAr[0])-12);
				}else if( ttmpAr[0] == 12 ){
					tmpX = "오후 " + ttmpAr[0];
				}else{
					tmpX = "오전 " + ttmpAr[0];
				}
				tmpResult = tmpX + ":" + ttmpAr[1];
			
			} else {
				tmpResult = tmpAr[0];
			}
			
			//날짜 변경을 위해 배열을 새로 만든다
			var tmpMap = new Map();
			tmpMap.put("isRead", lotmpDataSet.getList("mailInfoList")[i].get("isRead"));
			tmpMap.put("sendDate", lotmpDataSet.getList("mailInfoList")[i].get("sendDate"));
			tmpMap.put("receivedDate", tmpResult);
			tmpMap.put("hasAttachments", lotmpDataSet.getList("mailInfoList")[i].get("hasAttachments"));
			tmpMap.put("fromInfoName", lotmpDataSet.getList("mailInfoList")[i].get("fromInfoName"));
			tmpMap.put("mailTitle", lotmpDataSet.getList("mailInfoList")[i].get("mailTitle"));
			tmpMap.put("changeKey", lotmpDataSet.getList("mailInfoList")[i].get("changeKey"));
			tmpMap.put("mailId", lotmpDataSet.getList("mailInfoList")[i].get("mailId"));
			reDateDataSet.push(tmpMap);

			//상세보기에서 이전메일 다음메일을 보기위한 mailId배열 생성
			mailIdAr.push(lotmpDataSet.getList("mailInfoList")[i].get("mailId"));
			mailChangeKeyAr.push(lotmpDataSet.getList("mailInfoList")[i].get("changeKey"));
		};
		
		//리스트에 추가하는 경우 적용
		if(isAddData){
			loList.addData(reDateDataSet);
			addListDataSet = addListDataSet.concat(reDateDataSet);
			isAddData = false;
		}else{
			loList.setData(reDateDataSet);
			addListDataSet = reDateDataSet;
		}
		
		//리스트 마지막입니까? 아니면 더보기 버튼 활성화
		var loTotalPage = lotmpDataSet.get("totalPageCnt");
		var loPage		= parseInt(lotmpDataSet.get("page")) + 1;
	
		//전체페이지와 현재페이지 비교
		if ( loTotalPage > loPage ){
			document.getElementById('lastPanel' + selectTab).style.display = "none";
			document.getElementById('morePanel' + selectTab).style.display = "block";
		} else if ( loTotalPage = loPage ){
			document.getElementById('morePanel' + selectTab).style.display = "none";
			document.getElementById('lastPanel' + selectTab).style.display = "block";
		} else {
			alert("더보기버튼 관련 에러확인!");
		}
		
		//메일리스트 읽음, 파일첨부 표시
		var readColRenderer = new ColumnRenderer("isRead", {"true":"listStatusActive", "false":"listStatus"}, true);
		loList.addColumnRenderer(readColRenderer);
	
		var attachmentColRenderer = new ColumnRenderer("hasAttachments", {"true":"Attachment", "false":"NoAttachment"}, true);
		loList.addColumnRenderer(attachmentColRenderer);
		
	    nativeUI.dismissProgressDialog();
	  
	    //list click 관련
	    loList.setOnItemClickHandler(onListItemClick);
	    loList.setOnItemLongClickHandler(onListItemLongClick);
	    loList.itemFocusColor = "#ffb017";
		
	    loList.refresh(); 
		scrollView1.refresh();
		scrollView2.refresh();
		scrollView3.refresh();
		
	} else if (result == 7009){
		
		gmpUtil.loginGmp(authCallback, authErrorCallback);
		
	}else {
		
		if( confirm("처리에러\n Result Code : " + result + "\nresultMessage : \n" + resultMessage + "\n\n재시도 하시겠습니까?")){
			init();
		}else{
			nativeUI.dismissProgressDialog();
		};
	}
}

//Mail Delete - id + changekey
function mailDelRequest( loMailId, loMailChangeKey ){
	nativeUI.showProgressDialog();
	var tmpParams = new Object();
	tmpParams["function"] 	= "COMMON_MAIL_DELETE";
	tmpParams["ID"] 		= URLEncode(loMailId);
	tmpParams["CHANGEKEY"]	= URLEncode(loMailChangeKey);
	
	if(selectTab==3){
		tmpParams["isHardDel"]	= "true";
	}else{
		tmpParams["isHardDel"]	= "false";
	}
	
	var requestXml = xmlHandler.make(tmpParams);
	log.log("requestXml :: " + url + authInfo + requestXml);
	http.request( url + authInfo, "POST", tmpParams, getMailDelCallback, failureCallback );
	
}

//삭제요청, 안읽음표시 성공시 CallBack
function getMailDelCallback(){
	var xmlStr = http.response;	
	var tmpxml = (new DOMParser()).parseFromString(xmlStr, "text/xml");
	var result = tmpxml.getElementsByTagName("result")[0].firstChild.nodeValue;
	var resultMessage = tmpxml.getElementsByTagName("resultMessage")[0].firstChild.nodeValue;
	
	nativeUI.dismissProgressDialog();
	
	if(result == "1000") {
	
		log.log("MailDel SuccessResponseXml :: \n" + xmlStr);
		currentPage = 1;
		mailIdAr	= new Array();
		mailChangeKeyAr = new Array();
		receiveMailRequest();
		
	}else {
		
		if( confirm("처리에러\n Result Code : " + result + "\nresultMessage : \n" + resultMessage + "\n\n재시도 하시겠습니까?")){
			init();
		}
	}
}

//Mail UnRead - id + changekey
function mailIsReadRequest( loMailId, loMailChangeKey ){
	nativeUI.showProgressDialog();
	var tmpParams = new Object();
	tmpParams["function"] 	= "COMMON_MAIL_ISREAD";
	tmpParams["ID"] 		= URLEncode(loMailId);
	tmpParams["CHANGEKEY"]	= URLEncode(loMailChangeKey);
	tmpParams["ISREAD"]		= "false";
	
	var requestXml = xmlHandler.make(tmpParams);
	log.log("requestXml :: " + url + authInfo + requestXml);
	http.request( url + authInfo, "POST", tmpParams, getMailDelCallback, failureCallback );
	
}

function NgmsDBinit(){
	
	database.open("NgmsMA");
	
	try {
		var query = "CREATE TABLE IF NOT EXISTS ngms_ma_table (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, title TEXT  null, name TEXT null, content TEXT null, ref TEXT null, hidRef TEXT null, created TEXT null);";	
		database.executeUpdate( query , null );
	} catch(e) {
		alert("Database Exception: " + e);
	}
}

//임시편지함 DB
function tempMailRequest() {
	
	lastPanel4.setDisplay("block");
	nativeUI.showProgressDialog();
	
	var sqlStr = "SELECT * FROM ngms_ma_table order by id desc;";
	
	try {

		database.executeQuery(sqlStr, selectSuccessHandler_db, selectErrorHandler_db);
		
	} catch(e) {
		
		database.error = e;

	}
	
	if(database.error == null){
		
		log.log("Selecting data(name : ngms_ma_table) successful");
	
	} else {
		
		log.log("Selecting data error : " + database.error);
	
	}
	
}

function leadingZeros(n, digits) {

	var zero = '';
	n = n.toString();

	if (n.length < digits) {
	    for (i = 0; i < digits - n.length; i++)
	      zero += '0';
	}
	
	return zero + n;
}

function selectSuccessHandler_db(transaction, results) {
	
	var rows = results.rows;
	var row = null;
	array_db = new Array();

	try {
		
		for(var i = 0; i < rows.length; i++) {
			
			row = rows.item(i);
			var map_db = new Map();
			
			if (row["title"]=="" || row["title"]== null || row["title"]==" "){
					map_db.put("mailTitle","제목없음");
			}else{
					map_db.put("mailTitle",row["title"]);
			}
			
			map_db.put("content",row["content"]);
			map_db.put("fromInfoName",row["name"]);
			map_db.put("id", row["id"]);
			map_db.put("refInfo1", row["ref"]);
			map_db.put("hideInfo2", row["hidRef"]);
		
			var date 		  = new Date();
			var str  		  = row["created"];
			var yearMonDate   = leadingZeros(date.getFullYear(),4) + "" + leadingZeros(date.getMonth()+1,2) + "" + leadingZeros(date.getDate(),2);
			var dateMinAft 	  = "오후 " + "0" + (str.substr(8,2)-12) + ":" + str.substr(10,2);
			var dateMinAftTwl = "오후" + str.substr(8,2) + ":" + str.substr(10,2);
			var dateMinNight  = "오후 "+ (str.substr(8,2)-12) + ":" + str.substr(10,2);
			var dateMinMrn    = "오전 " + str.substr(8,2) + ":" + str.substr(10,2);
			var restOfDate 	  = str.substr(0,4) + "-" + str.substr(4,2) + "-" + str.substr(6,2);
			
			if(str.substr(0,8)== yearMonDate){
				
				if(str.substr(8,2)>"12" && str.substr(8,2)<="21"){
					map_db.put("receivedDate", dateMinAft);
				}else if (str.substr(8,2)>"21" && str.substr(8,2)<"24"){
					map_db.put("receivedDate", dateMinNight);	
				}else if(str.substr(8,2)=="12"){
					map_db.put("receivedDate", dateMinAftTwl);
				}				
				else{
					map_db.put("receivedDate", dateMinMrn);	
				}
			}else{
				map_db.put("receivedDate", restOfDate);	
			}	
			
			array_db.push(map_db);
		}	
		
	} catch(e) {
		
		alert("selectSuccessHandler error: " + e);
	
	}

	list4.setData(array_db);
	list4.setOnItemClickHandler(onListItemClick_db);
	list4.refresh(); 
	scrollView4.refresh();
	
	nativeUI.dismissProgressDialog();
}

function failureCallback() {
	log.error("Http Error:" + http.error);
	nativeUI.dismissProgressDialog();
	alert("통신상태 확인이 필요합니다. \n" + http.error );
	if(confirm("재시도 하시겠습니까?")){init()};
}

function selectErrorHandler_db(transaction, error) {

	alert("임시보관함에 저장된 내용이 없습니다.");
	nativeUI.dismissProgressDialog();

}

//Event
function initHandler(){
	
	tabToggle1.setOnClickHandler(setContent);
	tabPanel1.setOnClickHandler(setContent);
	tabImg1.setOnClickHandler(setContent);
	tabLabel1.setOnClickHandler(setContent);
	tabToggle2.setOnClickHandler(setContent);
	tabPanel2.setOnClickHandler(setContent);
	tabImg2.setOnClickHandler(setContent);
	tabLabel2.setOnClickHandler(setContent);
	tabToggle3.setOnClickHandler(setContent);
	tabPanel3.setOnClickHandler(setContent);
	tabImg3.setOnClickHandler(setContent);
	tabLabel3.setOnClickHandler(setContent);
	tabToggle4.setOnClickHandler(setContent);
	tabPanel4.setOnClickHandler(setContent);
	tabImg4.setOnClickHandler(setContent);
	tabLabel4.setOnClickHandler(setContent);

	tabBtn.setOnClickHandler(btnClick);
	widgetBtn.setOnClickHandler(btnClick);
	thememSelPanel.setOnClickHandler(btnClick);
	thememSelPanelIn.setOnClickHandler(btnClick);
	slideImg.setOnClickHandler(btnClick);
	widgetIconPanel.setOnClickHandler(btnClick);
	widgetClose.setOnClickHandler(btnClick);
	mailImg.setOnClickHandler(btnClick);
	boardImg.setOnClickHandler(btnClick);
	contactImg.setOnClickHandler(btnClick);
	scheduleImg.setOnClickHandler(btnClick);
	wtImg.setOnClickHandler(btnClick);

	searchSelPanel1.setOnClickHandler(textinputClicked);
	searchSelBtn1_1.setOnClickHandler(textinputClicked);
	searchSelBtnAll1.setOnClickHandler(btnClick);
	
	searchSelBtnAll2.setOnClickHandler(btnClick);
	searchSelBtnAll3.setOnClickHandler(btnClick);
	searchSelBtnAll4.setOnClickHandler(btnClick);
	seachInputBtn2_2.setOnClickHandler(btnClick);
	seachInputBtn3_2.setOnClickHandler(btnClick);
	seachInputBtn4_2.setOnClickHandler(btnClick);
	
	seachInputBtn1_1.setOnClickHandler(btnClick);
	seachInputBtn2_1.setOnClickHandler(btnClick);
	seachInputBtn3_1.setOnClickHandler(btnClick);
	seachInputBtn4_1.setOnClickHandler(btnClick);
	
	seachInputBtn1_2.setOnClickHandler(btnClick);
	seachInputLabel1.setOnClickHandler(btnClick);
	
	list4.setOnItemLongClickHandler(onListItemLongClick_db);
	
	optBtn1.setOnClickHandler(btnClick);
	optBtn2.setOnClickHandler(btnClick);
	optBtn3.setOnClickHandler(btnClick);
	optToolBarItem4.setOnClickHandler(btnClick);
	optBtn4.setOnClickHandler(btnClick);
	
	morePanelBtn1.setOnClickHandler(btnClick);
	morePanelBtn2.setOnClickHandler(btnClick);
	morePanelBtn3.setOnClickHandler(btnClick);
	morePanelBtn4.setOnClickHandler(btnClick);
	
	topBtn1.setOnClickHandler(btnClick);
	topLabel1.setOnClickHandler(btnClick);
	lastBtn1.setOnClickHandler(btnClick);
	lastLabel1.setOnClickHandler(btnClick);

	topBtn2.setOnClickHandler(btnClick);
	topLabel2.setOnClickHandler(btnClick);
	lastBtn2.setOnClickHandler(btnClick);
	lastLabel2.setOnClickHandler(btnClick);
	topBtn3.setOnClickHandler(btnClick);
	topLabel3.setOnClickHandler(btnClick);
	lastBtn3.setOnClickHandler(btnClick);
	lastLabel3.setOnClickHandler(btnClick);
	topBtn4.setOnClickHandler(btnClick);
	topLabel4.setOnClickHandler(btnClick);
	lastBtn4.setOnClickHandler(btnClick);
	lastLabel4.setOnClickHandler(btnClick);
	
	seachSortBtn1_1.setOnClickHandler(searchSortBtnClick);
	seachSortBtn1_2.setOnClickHandler(searchSortBtnClick);
	seachSortBtn1_3.setOnClickHandler(searchSortBtnClick);
	seachSortBtn1_4.setOnClickHandler(searchSortBtnClick);
	seachSortBtn2_1.setOnClickHandler(searchSortBtnClick);
	seachSortBtn2_2.setOnClickHandler(searchSortBtnClick);
	seachSortBtn2_4.setOnClickHandler(searchSortBtnClick);
	seachSortBtn3_1.setOnClickHandler(searchSortBtnClick);
	seachSortBtn3_2.setOnClickHandler(searchSortBtnClick);
	seachSortBtn3_3.setOnClickHandler(searchSortBtnClick);
	seachSortBtn3_4.setOnClickHandler(searchSortBtnClick);
	seachSortBtn4_1.setOnClickHandler(searchSortBtnClick);
	seachSortBtn4_2.setOnClickHandler(searchSortBtnClick);
	seachSortBtn4_4.setOnClickHandler(searchSortBtnClick);
	
	alopexController.setCustomizedBack(btnBackClick);
	
	thememSelPanel.setOnClickHandler(btnClick);
	thememSelPanelIn.setOnClickHandler(btnClick);
	slideImg.setOnClickHandler(btnClick);
	
	updatePanel.setOnClickHandler(update);
	updatePanelLabel.setOnClickHandler(update);
}

// Tab Click
function setContent(e) {
	
	switch ( e.target.id ){
		
		case "tabToggle1": 
		case "tabPanel1": 
		case "tabImg1": 
		case "tabLabel1":
			selectTab = 1;
			currentPage = 1;
			mailIdAr	= new Array();
			mailChangeKeyAr = new Array();
			receiveMailRequest();
			scrollView1.scrollTo(0, 0, null);
			tabDisplay( "recieveMailBox_tab" );
			modifyListClose();
			break;
			
		case "tabToggle2": 
		case "tabPanel2": 
		case "tabImg2": 
		case "tabLabel2":
			selectTab = 2;
			currentPage = 1;
			mailIdAr	= new Array();
			mailChangeKeyAr = new Array();
			receiveMailRequest();
			scrollView2.scrollTo(0, 0, null);
			tabDisplay( "sendMailBox_tab" );
			modifyListClose();
			break;
			
		case "tabToggle3": 
		case "tabPanel3": 
		case "tabImg3": 
		case "tabLabel3":
			selectTab = 3;
			currentPage = 1;
			mailIdAr	= new Array();
			mailChangeKeyAr = new Array();
			receiveMailRequest();
			scrollView3.scrollTo(0, 0, null);
			tabDisplay( "deleteMailBox_tab" );
			modifyListClose();
			break;
			
		case "tabToggle4": 
		case "tabPanel4": 
		case "tabImg4": 
		case "tabLabel4":
			tempMailRequest();
			selectTab = 4;
			scrollView4.scrollTo(0, 0, null);
			tabDisplay( "tempMailBox_tab" );
			modifyListClose();
			break;
	}
}


function btnClick(e){
	
	switch ( e.target.id ){
	
		case "tabBtn":
			tabPanelHidden();
			break;
			
		case "widgetBtn":
		case "widgetIconPanel":
		case "widgetClose":
			widgetChange();
			break;
			
		case "thememSelPanel":
		case "thememSelPanelIn":
		case "slideImg":
			changeTheme();
			break;
			
		case "searchSelBtn1_1":
			textinputClicked();
			break;
			
		case "searchSelBtnAll1":
			document.getElementById("searchSelPanel1").style.display = "none";
			document.getElementById("seachInputPanel1").style.display = "block";
			document.getElementById("seachSortPanel1").style.display = "block";
			if(tabHidden == 1){
				document.getElementById("scrollView1").style.height = "526px";
			}else{
				document.getElementById("scrollView1").style.height = "436px";
			}
			scrollView1.refresh();
			scrollView1.scrollTo(0, 0, null);
			list1.refresh(); 
			break;
		
		case "searchSelBtnAll2":
		case "searchSelBtnAll3":
		case "searchSelBtnAll4":
			document.getElementById( "searchSelPanel" + selectTab ).style.display = "none";
			document.getElementById( "seachInputPanel" + selectTab ).style.display = "block";
			document.getElementById( "seachSortPanel" + selectTab ).style.display = "block";
			if(tabHidden == 1){
				document.getElementById("scrollView" + selectTab ).style.height = "526px";
			}else{
				document.getElementById( "scrollView" + selectTab ).style.height = "436px";
			}
			document.getElementById( "scrollView" + selectTab ).refresh();
			document.getElementById( "scrollView" + selectTab ).scrollTo(0, 0, null);
			//document.getElementById( "list" + selectTab ).refresh(); 
			break;
	
		case "seachInputBtn1_1":
			inputValue1 = seachInputTxtField1.getText();
			if(inputValue1.length < 2){
				alert("검색어는 2자 이상 입력하여야 합니다.");
			} else {
				receiveMailRequest(inputValue1);
			}
			break;
			
		case "seachInputBtn2_1":	
			inputValue2 = seachInputTxtField2.getText();
			if(inputValue2.length < 2){
				alert("검색어는 2자 이상 입력하여야 합니다.");
			} else {
				receiveMailRequest(inputValue2);
			}
			break;
		
		case "seachInputBtn3_1":
			inputValue3 = seachInputTxtField3.getText();
			if(inputValue3.length < 2){
				alert("검색어는 2자 이상 입력하여야 합니다.");
			} else {
				receiveMailRequest(inputValue3);
			}
			break;
			
		case "seachInputBtn4_1":
						
			
			inputValue4 =seachInputTxtField4.getText();
			
			if(inputValue4.length < 2){
			 	alert("검색어는 2자 이상 입력하여야 합니다.");
			} else {
			
			nativeUI.showProgressDialog();

				database.open("NgmsMA");
				
				var sqlStr = "SELECT * FROM ngms_ma_table order by id desc;";
				try {
					database.executeQuery(sqlStr, selectSuccessHandler_db_search, selectErrorHandler_db);					
				} catch(e) {		
					database.error = e;
				}				
				if(database.error != null){					
					log.log("Selecting data(name : ngms_ma_table) successful");				
				} else {					
					log.log("Selecting data error : " + database.error);				
				}				
			}
			
			function selectSuccessHandler_db_search(transaction, results) {
				
				var rows = results.rows;
				var row = null;

				array_db = new Array();

				try {
							
					for(var i = 0; i < rows.length; i++) {
						row = rows.item(i);
						
						var map_db = new Map();
						
						map_db.put("mailTitle",row["title"]);
						map_db.put("content",row["content"]);
						map_db.put("fromInfoName",row["name"]);
						map_db.put("id", row["id"]);
						map_db.put("refInfo1", row["ref"]);
						map_db.put("hideInfo2", row["hidRef"]);
						map_db.put("receivedDate", row["created"]);
						
						var date = new Date();
						var str  = row["created"];
						var yearMonDate = leadingZeros(date.getFullYear(),4) + "" + leadingZeros(date.getMonth()+1,2) + "" + leadingZeros(date.getDate(),2);
						
						var dateMinAft = "오후 " + "0" + (str.substr(8,2)-12) + ":" + str.substr(10,2);
						var dateMinAftTwl = "오후" + str.substr(8,2) + ":" + str.substr(10,2);
						var dateMinNight = "오후 "+ (str.substr(8,2)-12) + ":" + str.substr(10,2);
						var dateMinMrn = "오전 " + str.substr(8,2) + ":" + str.substr(10,2);
						var restOfDate = str.substr(0,4) + "-" + str.substr(4,2) + "-" + str.substr(6,2);
						
						if(str.substr(0,8)== yearMonDate){
							if(str.substr(8,2)>"12" && str.substr(8,2)<="21"){
								map_db.put("receivedDate", dateMinAft);
							}else if (str.substr(8,2)>"21" && str.substr(8,2)<"24"){
								map_db.put("receivedDate", dateMinNight);	
							}else if(str.substr(8,2)=="12"){
								map_db.put("receivedDate", dateMinAftTwl);
							}				
							else{
								map_db.put("receivedDate", dateMinMrn);	
							}
						}else{
							map_db.put("receivedDate", restOfDate);	
						}

						if(document.getElementById( "seachSortBtn" + 4 + "_" + 2 ).className == "seachSortBtn" && document.getElementById( "seachSortBtn" + 4 + "_" + 4 ).className == "seachSortBtn" ){
							if (inputValue4 == row["name"] || inputValue4== row["title"])	{
								array_db.push(map_db);
							} 
						} else if (document.getElementById( "seachSortBtn" + 4 + "_" + 1 ).className == "seachSortBtn" && document.getElementById( "seachSortBtn" + 4 + "_" + 4 ).className == "seachSortBtn"){
							if (inputValue4 == row["name"])	{
								array_db.push(map_db);
							}
						} else if (document.getElementById( "seachSortBtn" + 4 + "_" + 1 ).className == "seachSortBtn" && document.getElementById( "seachSortBtn" + 4 + "_" + 2 ).className == "seachSortBtn"){
							if (inputValue4 == row["title"])	{
								array_db.push(map_db);
							}
						}
					}	
				} catch(e) {
					alert("selectSuccessHandler error: " + e);
				}

				list4.setData(array_db);
				list4.setOnItemClickHandler(onListItemClick_db);
				list4.refresh(); 
				scrollView4.refresh();
				nativeUI.dismissProgressDialog();
			}
			break;
			
		case "seachInputBtn1_2":
		case "seachInputBtn2_2":
		case "seachInputBtn3_2":
		case "seachInputLabel1":
		case "seachInputLabel2":
		case "seachInputLabel3":
			scrollViewHeightInit();
			break;
		
		case "seachInputLabel4":	
		case "seachInputBtn4_2": 
		case "optToolBarItem1":
			scrollViewHeightInit();
			tempMailRequest();
			break;
		
		case "mailImg":
			alert("메일앱");
			break;
			
		case "boardImg":
			alert("게시판앱");
			break;
		
		case "contactImg":
			alert("주소록앱");
			break;
			
		case "scheduleImg":
			alert("스케줄러앱");
			break;
			
		case "wtImg":
			alert("winstops");
			break;
			
		case "hiskImg":
			alert("hisk");
			break;
		
		case "optBtn1":
		case "optLabel1":
			modifyListClose();
			break;
			
		case "optToolBarItem2":
		case "optBtn2":
		case "optLabel2":
			
			var loTmpIndex = "";
			var loMailId = "";
			var loMailChangeKey = "";
			
			if(selectTab==1){
			for(var i=0; i < document.getElementsByName("listCheck" + selectTab).length; i++){
	
				if(document.getElementsByName("listCheck"  + selectTab )[i].className == "CheckBoxActive"){
					loTmpIndex += i + ", ";
					loMailId += addListDataSet[i].get("mailId") + ";";
					loMailChangeKey += addListDataSet[i].get("changeKey") + ";";
				}
			}
			
			if(loTmpIndex==""){
				alert("선택된 메일이 없습니다.")
			}else{
				loMailId = loMailId.substring(0, loMailId.length-1);
				loMailChangeKey = loMailChangeKey.substring(0, loMailChangeKey.length-1);
				log.log("loMailId : " +loMailId +"\nloMailChangeKey : "+loMailChangeKey);
				mailIsReadRequest( loMailId, loMailChangeKey );
			}
			}else{
				alert('임시보관함은 구현 예정 없습니다');
			}
			break;
			
		case "optToolBarItem3":
		case "optBtn3":
		case "optLabel3":
			
			var loTmpIndex = "";
			var loMailId = "";
			var loMailChangeKey = "";
						
			for(var i=0; i < document.getElementsByName("listCheck" + selectTab).length; i++){
				if(document.getElementsByName("listCheck"  + selectTab )[i].className == "CheckBoxActive"){
					
					loTmpIndex += i + ", ";
					loMailId += addListDataSet[i].get("mailId") + ";";
					loMailChangeKey += addListDataSet[i].get("changeKey") + ";";
				}
				
			}if(loTmpIndex==""){  //-------------- 메일을 아무것도 선택하지 않았을 시에 보여주는 alert.
				
				alert("선택된 메일이 없습니다.");
				return;
				
			}else if(selectTab!=4){  //-----------임시보관함 외의 다른 탭을 클릭했을때 처리 과정
				
				mailDelRequest( loMailId, loMailChangeKey );
				log.log("loMailId : " +loMailId +"\nloMailChangeKey : "+loMailChangeKey);		
				
				}else{  //------------------------임시보관함을 클릭했을때 처리과정
					for(var j=0; j < document.getElementsByName("listCheck" + selectTab).length; j++){
					if(document.getElementsByName("listCheck"  + selectTab )[j].className == "CheckBoxActive"){
						
					var sqlStr = null;
				
					database.open("NgmsMA");
					nativeUI.showProgressDialog();	
									
					sqlStr = "DELETE FROM ngms_ma_table WHERE id='" + array_db[j].get("id")+ "';";
									
					try {
								
					database.executeQuery(sqlStr, selectSuccessHandler_multi_db, selectErrorHandler_long_db);
										
					} catch(e) {
						database.error = e;
					}
									
						if(database.error != null)
							log.log("Deleting data(name : ngms_ma_table) successful");
						else
						    log.log("Deleting data error : " + database.error);
									
						function selectSuccessHandler_multi_db(){
							nativeUI.dismissProgressDialog();			
									}
								}
							}
							tempMailRequest();
						}
			break;
		
		case "optoptToolBarItem4":
		case "optBtn4":
		case "optLabel4":
			if( allChecked == 0 ){
				for( var i = 0; i < document.getElementsByName("listCheck"  + selectTab ).length; i++){
					document.getElementsByName("listCheck"  + selectTab )[i].className = "CheckBoxActive";
					document.getElementsByName("listRow" + selectTab )[i].className = "ListRowChecked";
					allChecked = 1;
				} 
			} else {
				for( var i = 0; i < document.getElementsByName("listCheck"  + selectTab ).length; i++){
					document.getElementsByName("listCheck" + selectTab )[i].className = "CheckBox";
					document.getElementsByName("listRow" + selectTab )[i].className = "ListRow";
					allChecked = 0;
				}
			}
			break;
			
		case "morePanelBtn1":
		case "moreLabel1":
			isAddData = true; 
			currentPage += currentPage;
			receiveMailRequest();
			break;
			
		case "morePanelBtn2":
		case "moreLabel2":
			isAddData = true; 
			currentPage += currentPage;
			receiveMailRequest();
			break;
		
		case "morePanelBtn3":
		case "moreLabel3":
			isAddData = true; 
			currentPage += currentPage;
			receiveMailRequest();
			break;
		
		case "topBtn1":
		case "topLabel1":
		case "lastBtn1":		
		case "lastBtnLabel1":
			scrollView1.scrollTo(0, 0, null);
			break;	
			
		case "topBtn2":
		case "topLabel2":
		case "lastBtn2":
		case "lastBtnLabel2":
			scrollView2.scrollTo(0, 0, null);
			break;
			
		case "topBtn3":
		case "topLabel3":
		case "lastBtn3":
		case "lastBtnLabel3":
			scrollView3.scrollTo(0, 0, null);
			break;	
			
		case "topBtn4":
		case "topLabel4":
		case "lastBtn4":
		case "lastBtnLabel4":
			scrollView4.scrollTo(0, 0, null);
			break;
	}
}

function searchSortBtnClick(e){
	
	switch ( selectTab ){
	
		case 1:
			for ( var i = 1; i < 5; i++ ){
				document.getElementById( "seachSortBtn" + selectTab + "_" + i ).className = "seachSortBtn";
			}
			break;
			
		case 2:
		case 4:
			for ( var i = 1; i < 5; i++ ){
				if( i != 3 ){
					document.getElementById( "seachSortBtn" + selectTab + "_" + i ).className = "seachSortBtn";
				}
			}
			break;
			
		case 3:
			for ( var i = 1; i < 5; i++ ){
				document.getElementById( "seachSortBtn" + selectTab + "_" + i ).className = "seachSortBtn";

			}
			break;
	}
	var tmpId = e.target.id.replace("Label","Btn");
	document.getElementById( tmpId ).className = "seachSortBtnFocus";
	
	//KeyWord Search
	var tmpSearchRange = null; 
	switch ( tmpId ){
		
		case "seachSortBtn1_1":
		case "seachSortBtn2_1":
		case "seachSortBtn3_1":
		case "seachSortBtn4_1":	
			tmpSearchRange = "G";
			break;
			
		case "seachSortBtn1_2":
		case "seachSortBtn2_2":
		case "seachSortBtn3_2":
		case "seachSortBtn4_2":
			tmpSearchRange = "E";
			break;
		
		case "seachSortBtn3_3":
		case "seachSortBtn1_3":
			tmpSearchRange = "F";
			break;
			
		case "seachSortBtn1_4":
		case "seachSortBtn2_4":
		case "seachSortBtn3_4":
		case "seachSortBtn4_4":
			tmpSearchRange = "D";
			break;
	}
	
	searchRangeAr[selectTab]=tmpSearchRange;
	
}

function btnBackClick(){

	if ( widgetBtn == 1 ){
		widgetChange();
	} else if ( tabHidden == 1 ){
		tabPanelHidden();
	} else if( modifying == 1 ){
		modifyListClose();
	} else {
		if( confirm("종료하시겠습니까?") ){
			alopexController.exit();
		}
	}
	alopexController.setCustomizedBack(btnBackClick);
}

//개인설정 폴더 보기
function textinputClicked(){
	//...
	nativeUI.setContextMenuItem("전체 ", search1);
//	nativeUI.setContextMenuItem("A편지함", search2);
//	nativeUI.setContextMenuItem("B편지함", search3);
	nativeUI.showContextMenu();
	
//	현재 폴더생성이 불가능하여 진행불가 
//	nativeUI.showProgressDialog();
//	var tmpParams = new Object();
//	tmpParams["function"] 	= "COMMON_MAIL_MAILBOX";
//	
//	var requestXml = xmlHandler.make(tmpParams);
//	log.log("requestXml :: " + url + authInfo + requestXml);
//	alert(requestXml);
//	http.request( url + authInfo, "POST", tmpParams, mailBoxCallback, failureCallback );
	
}

function mailBoxCallback(){
	var xmlStr = http.response;	
	var tmpxml = (new DOMParser()).parseFromString(xmlStr, "text/xml");
	var result = tmpxml.getElementsByTagName("result")[0].firstChild.nodeValue;
	var resultMessage = tmpxml.getElementsByTagName("resultMessage")[0].firstChild.nodeValue;
	nativeUI.dismissProgressDialog();
	
	if(result == "1000") {
		log.log("MailDel SuccessResponseXml :: \n" + xmlStr);
		currentPage = 1;
	}else {
		if( confirm("처리에러\n Result Code : " + result + "\nresultMessage : \n" + resultMessage + "\n\n재시도 하시겠습니까?")){
			init();
		}
	}
}

//Tab Display
function tabDisplay( asCmd ) {
	
	var lsrContainer = [ "recieveMailBox_tab" , "sendMailBox_tab" , "deleteMailBox_tab" , "tempMailBox_tab" ];
	if( typeof asCmd == "undefined" ) {
		for( var i = 1 ; i <= lsrContainer.length ; i++ ) {
			document.getElementById( lsrContainer[i-1] ).style.display = "none";
			document.getElementById( "tabToggle" + i ).className = "Toggle";
		}
	} else {
		tabDisplay();
		document.getElementById( asCmd ).style.display = "block";
		document.getElementById( "tabToggle" + (selectTab)).className = "ToggleActive";
		recentlySelectTab = asCmd;
	}
}


//Theme Skin
function checkTheme(){
	if(preference.getString( key_theme, "") == ""){
		preference.putString( key_theme, selectTheme );
	}
	selectTheme = preference.getString(key_theme);
	
	if ( selectTheme == "black" ){
		document.getElementById("themePanel").className = "themePanel_b";
		document.getElementById("slideImg").className = "ImageW";
	} else if ( selectTheme == "white" ){
		document.getElementById("themePanel").className = "themePanel_w";
		document.getElementById("slideImg").className = "Image";
	} 
}

function changeTheme(){
	
	if ( selectTheme == "black" ){ 
		document.getElementById("slideImg").className = "ImageW";
		selectTheme = "white"; 
	} else if ( selectTheme == "white" ){ 
		document.getElementById("slideImg").className = "Image";
		selectTheme = "black"; 
	}
	preference.putString( key_theme, selectTheme );
	checkTheme();
}

//iPhone Back Button
function checkFlatform(){
	
	if(device.platformName == "iPhone") {
		middle.setData("Back");
		titleBarBackButton.setOnClickHandler(btnBackClick);
	}
}

//Tab4 ClickHandler
function onListItemClick_db(e){
	var tmpIndex_db = e.currentTarget.index;

	if ( modifying == 0 ){
//		var db_id		= array_db[tmpIndex_db].get("id");
//		var db_name 	= array_db[tmpIndex_db].get("fromInfoName");
//		var db_content 	= array_db[tmpIndex_db].get("content");
//		var db_title 	= array_db[tmpIndex_db].get("mailTitle");
//		var db_ref 		= array_db[tmpIndex_db].get("refInfo1");
//		var db_hidRef 	= array_db[tmpIndex_db].get("hideInfo2");
//		var mailType 	= "tempWrite";
		
		var tmpParams = new Object();
		tmpParams["db_id"] 		= array_db[tmpIndex_db].get("id");
		tmpParams["db_name"] 	= array_db[tmpIndex_db].get("fromInfoName");
		tmpParams["db_content"] = array_db[tmpIndex_db].get("content");
		tmpParams["db_title"] 	= array_db[tmpIndex_db].get("mailTitle");
		tmpParams["db_ref"] 	= array_db[tmpIndex_db].get("refInfo1");
		tmpParams["db_hidRef"] 	= array_db[tmpIndex_db].get("hideInfo2");
		tmpParams["mailType"] 	= "tempWrite";
		
		//alert(db_id+"\n"+db_name+"\n"+db_content+"\n"+db_title+"\n"+db_ref+"\n"+db_hidRef+"\n"+mailType);
		alopexController.navigateWithParameters("Mail_Write",tmpParams);
	
	} else {
		
    	if ( document.getElementsByName("listCheck4")[ tmpIndex_db ].className == "CheckBox" ){
    		document.getElementsByName("listCheck4")[ tmpIndex_db ].className = "CheckBoxActive";
    		document.getElementsByName("listRow4")[ tmpIndex_db].className = "ListRowChecked";
    	} else if( document.getElementsByName("listCheck4")[ tmpIndex_db ].className == "CheckBoxActive" ){
    		document.getElementsByName("listCheck4")[ tmpIndex_db ].className = "CheckBox";
    		document.getElementsByName("listRow4")[tmpIndex_db].className = "ListRow";
    	} else {
    		alert( "list_biz Line 1014 확인 " );
    	}

	}
}

// listItem click 
function onListItemClick(e) {
	var tmpIndex = e.currentTarget.index;
	
    if ( modifying == 0 ){
    	var itemData 	= eval("("+"list"+selectTab+")").getDataAt( tmpIndex );
	    var mailId 		= itemData.get("mailId");
	    var changeKey 	= itemData.get("changeKey");

	    alopexController.navigateWithParameters("Mail_View", {"authInfo" : authInfo, "mailId": mailId, "changeKey" : changeKey, "mailIdAr" : mailIdAr, "mailChangeKeyAr" : mailChangeKeyAr, "mailIdIndex" : tmpIndex});
	    
    } else {
    	
    	if ( document.getElementsByName("listCheck" + selectTab )[ tmpIndex ].className == "CheckBox" ){
    		document.getElementsByName("listCheck" + selectTab )[ tmpIndex ].className = "CheckBoxActive";
    		document.getElementsByName("listRow"  + selectTab )[ tmpIndex].className = "ListRowChecked";
    	} else if( document.getElementsByName("listCheck"  + selectTab )[ tmpIndex ].className == "CheckBoxActive" ){
    		document.getElementsByName("listCheck"  + selectTab )[ tmpIndex ].className = "CheckBox";
    		document.getElementsByName("listRow"  + selectTab )[tmpIndex].className = "ListRow";
    	} else {
    		alert( "list_biz onListItemClick 확인 " );
    	}
    }
}

//listItem longclick 
function onListItemLongClick(e) {
	longClickTarget = e;
	
	nativeUI.setContextMenuItem("삭제하기", selectedDelete);
	
	if(selectTab==1){
		nativeUI.setContextMenuItem("안읽음표시", selectedUnread);
	}
	
	nativeUI.showContextMenu();

}

function onListItemLongClick_db(e){
	longClickTarget = e;
	nativeUI.setContextMenuItem("삭제하기", selectedDelete_db);
	nativeUI.showContextMenu();
}

function setLocalMenu(){
	menu.removeAll();
	menu.add("업데이트", update, "update");
	menu.add("서명설정", setSignature, "signature");
	menu.add("선택", modifyList, "modify");
	menu.add("메일작성", mailWrite, "write");
}

function update() {
	init();
}

function setSignature() {
	alopexController.navigateWithParameters("Mail_Sign",{"authInfo":authInfo});
}

function tabPanelHidden(){
	
	if ( tabHidden == 0 ){
		tabHidden = 1;
		document.getElementById("menuTabBar").style.display = "none";
		document.getElementById("tabBtn").className = "tabBtnclose";
		
		document.getElementById("scrollView1").style.height = "585px";
		document.getElementById("scrollView2").style.height = "585px";
		document.getElementById("scrollView3").style.height = "585px";
		document.getElementById("scrollView4").style.height = "585px";
		
	} else if ( tabHidden == 1 ){
		tabHidden = 0;
		document.getElementById("menuTabBar").style.display = "block";
		document.getElementById("tabBtn").className = "tabBtn";
		
		document.getElementById("scrollView1").style.height = "492px";
		document.getElementById("scrollView2").style.height = "492px";
		document.getElementById("scrollView3").style.height = "492px";
		document.getElementById("scrollView4").style.height = "492px";

	}
	scrollViewHeightInit();
	
	scrollView1.refresh(); 
	scrollView2.refresh();
	scrollView3.refresh();
	scrollView4.refresh();
	scrollView1.scrollTo(0, 0, null);
	scrollView2.scrollTo(0, 0, null);
	scrollView3.scrollTo(0, 0, null);
	scrollView4.scrollTo(0, 0, null);
}

function widgetChange(){
	if ( widgetBtn == 0 ){
		widgetBtn = 1;
		document.getElementById("widgetPanel").style.display = "block";
	} else {
		widgetBtn = 0;
		scrollViewHeightInit();
	}
}

function scrollViewHeightInit(){
	
		document.getElementById("widgetPanel").style.display = "none";
		
		document.getElementById("seachInputPanel1").style.display = "none";
		document.getElementById("seachInputPanel2").style.display = "none";
		document.getElementById("seachInputPanel3").style.display = "none";
		document.getElementById("seachInputPanel4").style.display = "none";
		
		document.getElementById("seachSortPanel1").style.display = "none";
		document.getElementById("seachSortPanel2").style.display = "none";
		document.getElementById("seachSortPanel3").style.display = "none";
		document.getElementById("seachSortPanel4").style.display = "none";
	
		document.getElementById("searchSelPanel1").style.display = "block";
		document.getElementById("searchSelPanel2").style.display = "block";
		document.getElementById("searchSelPanel3").style.display = "block";
		document.getElementById("searchSelPanel4").style.display = "block";
	
	if(tabHidden==0){
		document.getElementById("menuTabBar").style.display = "block";
		
		document.getElementById("scrollView1").style.height = "492px";
		document.getElementById("scrollView2").style.height = "492px";
		document.getElementById("scrollView3").style.height = "492px";
		document.getElementById("scrollView4").style.height = "492px";
		
	}else{
		
		document.getElementById("scrollView1").style.height = "585px";
		document.getElementById("scrollView2").style.height = "585px";
		document.getElementById("scrollView3").style.height = "585px";
		document.getElementById("scrollView4").style.height = "585px";
		
	}
		
	scrollView1.refresh(); 
	scrollView2.refresh();
	scrollView3.refresh();
	scrollView4.refresh();
	scrollView1.scrollTo(0, 0, null);
	scrollView2.scrollTo(0, 0, null);
	scrollView3.scrollTo(0, 0, null);
	scrollView4.scrollTo(0, 0, null);
	
}

//Check Mode
function modifyList(){
	modifying = 1;
	document.getElementById("optToolBar1").style.display = "block";
	document.getElementById( "list" + selectTab ).className = "ListChecked";
	
	for( var i = 0; i < document.getElementsByName( "listCheck"  + selectTab ).length; i++){
		document.getElementsByName("listCheck"  + selectTab )[i].style.display = "block";
	};
}

function modifyListClose(){
	modifying = 0;
	document.getElementById("optToolBar1").style.display = "none";
	
	for( var i = 1; i < 5; i++ ){
		document.getElementById( "list" + i ).className = "List" + i;
	}
	
	for( var i = 0; i < document.getElementsByName("listCheck"  + selectTab ).length; i++){
		document.getElementsByName("listCheck"  + selectTab )[i].style.display = "none";
		document.getElementsByName("listCheck"  + selectTab )[i].className = "CheckBox";
		document.getElementsByName("listRow"  + selectTab )[i].className = "ListRow";
	};

}

function mailWrite(){
	alopexController.navigateWithParameters("Mail_Write",{"authInfo":authInfo});
}

//Delete Mail
function selectedDelete(e) {
	
	var tmpIndex	= longClickTarget.currentTarget.index;
	var loMailTitle = addListDataSet[tmpIndex].get("mailTitle");
	var loMailId = addListDataSet[tmpIndex].get("mailId");
	var loMailChangeKey = addListDataSet[tmpIndex].get("changeKey");
	mailDelRequest( loMailId, loMailChangeKey );
}

//UnRead Mail
function selectedUnread(e){

	var tmpIndex	= longClickTarget.currentTarget.index;
	var loMailTitle = addListDataSet[tmpIndex].get("mailTitle");
	var loMailId = addListDataSet[tmpIndex].get("mailId");
	var loMailChangeKey = addListDataSet[tmpIndex].get("changeKey");
	mailIsReadRequest( loMailId, loMailChangeKey );
}

function selectedDelete_db(){
	
	var e = longClickTarget;
	var tmpIndex_long_db = e.currentTarget.index;
	var sqlStr = null;
	var db_long_id	=  null;
	
	database.open("NgmsMA");
	db_long_id = (array_db[tmpIndex_long_db].get("id"));
	sqlStr = "DELETE FROM ngms_ma_table WHERE id='" + db_long_id+ "';";
	
	try {
		database.executeQuery(sqlStr, selectSuccessHandler_long_db, selectErrorHandler_long_db);
	} catch(e) {
		database.error = e;
	}
	
	if(database.error != null)
		log.log("Deleting data(name : ngms_ma_table) successful");
	else
		log.log("Deleting data error : " + database.error);
}

function selectErrorHandler_long_db() {
	alert("지울  내용이 없습니다.");
}

function selectSuccessHandler_long_db() {
	alert('삭제 하였습니다 ');
	tempMailRequest();
}

function search1(){
	searchSelLabel1_1.setData("받은 편지함 - 전체  ");
}

function search2(){
	searchSelLabel1_1.setData("A편지함");
}

function search3(){
	searchSelLabel1_1.setData("B편지함");
}
